package com.yiren.manager.service.impl.base;

import javax.transaction.Transactional;

import org.hibernate.annotations.AttributeAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrElderPayRecord;
import com.yiren.entity.YrElderWallet;
import com.yiren.entity.YrMealCard;
import com.yiren.entity.YrStaffPayRecord;
import com.yiren.entity.YrUserRfidCard;
import com.yiren.manager.repository.base.YrUserRfidCardRepository;
import com.yiren.manager.repository.cost.YrElderPayRecordRepository;
import com.yiren.manager.repository.department.YrStaffPayRecordRepository;
import com.yiren.manager.repository.elder.YrElderWalletRepository;
import com.yiren.manager.repository.messhall.YrMealCardRepositoty;
import com.yiren.manager.service.iface.base.YrUserRfidCardService;

@Service
public class YrUserRfidCardServiceImpl extends GenericServiceImpl<YrUserRfidCard, String> implements YrUserRfidCardService{

	@Autowired
	private YrMealCardRepositoty mealCardRepositoty;
	
	@Autowired
	private YrElderWalletRepository elderWalletRepository;
	
	@Autowired
	private YrElderPayRecordRepository elderPayRecordRepository;
	
	@Autowired
	private YrStaffPayRecordRepository staffPayRecordRepository;
	
	
	@Autowired
	public YrUserRfidCardServiceImpl(YrUserRfidCardRepository repository) {
		super(repository);
	}

	@Transactional
	public void addByFavorites(Favorites entitys) throws MyException {
		
		YrUserRfidCard entity = entitys.getFavorite(YrUserRfidCard.class);
		YrMealCard mealCard = entitys.getFavorite(YrMealCard.class);
		YrElderWallet elderWallet = entitys.getFavorite(YrElderWallet.class);
		YrElderPayRecord elderPayRecord = entitys.getFavorite(YrElderPayRecord.class);
		YrStaffPayRecord staffPayRecord = entitys.getFavorite(YrStaffPayRecord.class);
		
		this.repository.save(entity);
		if(null!=mealCard){
			mealCardRepositoty.save(mealCard);
		}
		if(null!=elderWallet){
			elderWalletRepository.save(elderWallet);
		}
		if(null!=elderPayRecord){
			elderPayRecordRepository.save(elderPayRecord);
		}
		if(null!=staffPayRecord){
			staffPayRecordRepository.save(staffPayRecord);
		}
	}

}
